package com.example.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @author wangbin
 */
public class JSON {
    public static String toJson(Object object) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        return om.writeValueAsString(object);
    }

    public static <T> T fromJson(String json, Class<T> convertClass) throws IOException {
        ObjectMapper om = new ObjectMapper();
        return om.readValue(json, convertClass);
    }
}
